package de.mmis.core.base.abstracttree.serializer;

import de.mmis.core.base.abstracttree.Tree;

/**
 * Exceptions thrown while deserializing, indicating the given {@link Tree} is
 * not deserializable into an object using this deserializer
 * 
 * @author Christian Koch
 */
public class DeserializableException extends Exception {

	private static final long serialVersionUID = 3212457154169665624L;
	private Tree exp;

	public DeserializableException(Tree exp) {
		this(exp, null, null);
	}

	public DeserializableException(Tree exp, Exception exception) {
		this(exp, exception, null);
	}

	public DeserializableException(Tree exp, String reason) {
		this(exp, null, reason);
	}

	public DeserializableException(Tree exp, Throwable cause, String reason) {
		super(reason, cause);
		this.exp = exp;
	}

	@Override
	public String toString() {
		return "Could not unmarshall an object from the given Tree \""
				+ this.exp
				+ "\""
				+ ((getMessage() != null) ? " (Reason: " + getMessage() + ")"
						: "");
	}
}